// import { useStore} from '@/store' //hasInfo获不到值
// const store:any = useStore();

const hasInfo=()=>{
	// const userInfo = store.state.user.user
	const userInfo = uni.$store.state.user.user
	return userInfo && userInfo.id
}
const navTo=(path, params = {},opt:any={})=> {
	// console.log("===this.userInfo",this.userInfo,uni.$store.state.user.user);
	let objParams = params;
	opt={type:'push',isCheckLogin:false ,...opt}; //opt传一值补全
	if(opt.isCheckLogin && !hasInfo()){
		uni.navigateTo({
			url:'/pages/login/login'
		})
		return;
	}
	// 是否跳转外部链接
	if (path.indexOf('http')>-1) {
		// #ifdef H5
		window.location = path;
		// #endif
		// #ifndef  H5
		uni.navigateTo({
			url:'/pages/public/webview?webviewPath='+path
		})
		// #endif
		return false
	}
	let navObj={
		push:'navigateTo',
		replace:'redirectTo',
		replaceAll:'reLaunch',
		pushTab:'switchTab',
	}
	let pathUrl=path;
	// console.log('navTo 2--')
	if(objParams && typeof objParams ==='object' && Object.keys(objParams).length > 0){
		let pathArr=[];
		Object.keys(objParams).forEach(k =>{
			pathArr.push(`${k}=${objParams[k]}`);
		})
		pathUrl = path +'?'+pathArr.join('&');
	}
	// console.log('---',navObj[opt.type],pathUrl)
	uni[navObj[opt.type]]({
		url:pathUrl
	})
}
const goBack=(delta=1)=>{
	uni.navigateBack({
		delta,
		fail: (err) => {
			// console.log('err---',err)
			navTo('/pages/index/index',{},{type:'replaceAll'})
		}
	});
}

export default {
	hasInfo,
	navTo,
	goBack,
}